package com.buss.product.model;

import java.io.Serializable;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.TableGenerator;

import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import com.buss.core.dic.RecordStatus;

@Entity
@Table(name="base_goodscategory")
@TableGenerator(name="goodscategory_pk_sequence",initialValue=1,allocationSize=1,pkColumnName="seq_col",
		pkColumnValue="goodscategory_seq",valueColumnName="seq_val",table="product_pk_sequence")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@JsonIgnoreProperties(value={"brands","propGroup"})
public class GoodsCategory implements Serializable {

	private static final long serialVersionUID = 7824817178465976321L;

	/**分类ID*/
	@Id
	@GeneratedValue(strategy=GenerationType.TABLE,generator="goodscategory_pk_sequence")
	private Long id;
	
	/**分类编码*/
	@Column(nullable=false,length=20)
	private String code;
	
	/**分类名称*/
	@Column(nullable=false,length=100)
	private String name;
	
	/**单位编码*/
	@Column(nullable=false,length=20)
	private String companyId;
	
	/**该商品分类用于分店/库房编码，(存储方式：库房1，库房2，库房3)，0表示多有分店/库房都可以使用该分类*/
	@Column(nullable=false,length=4000)
	private String branchId;
	
	/**分类描述*/
	@Column(length=500)
	private String intro;
	
	/**上级编码，如果是顶级分类，值为0*/
	@Column(nullable=false)
	private Long parentId;
	
	/**排序序号*/	
	private Long sortOrder;
	
	/**直接子分类数*/
	@Column(updatable = false)
	private Integer subCategories;
	
	/**状态：normal:正常，deleted：已删除，disabled：不可用. 默认为：normal*/
	@Column(nullable=false,length=20)
	@Enumerated(value=EnumType.STRING)
	private RecordStatus status;

	@ManyToMany(cascade = CascadeType.REFRESH,fetch=FetchType.LAZY)
	@JoinTable(name="base_category_brand",inverseJoinColumns={@JoinColumn(name="brandId")},
			joinColumns={@JoinColumn(name="categoryId") })
	private List<Brand> brands;
	
	
	@ManyToMany(cascade = CascadeType.REFRESH,fetch=FetchType.LAZY)
	@JoinTable(name="base_category_propgroup",inverseJoinColumns={@JoinColumn(name="groupId")},
			joinColumns={@JoinColumn(name="categoryId")})
	private List<CatePropGroup> propGroups;
	
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getCompanyId() {
		return companyId;
	}

	public void setCompanyId(String companyId) {
		this.companyId = companyId;
	}

	public String getBranchId() {
		return branchId;
	}

	public void setBranchId(String branchId) {
		this.branchId = branchId;
	}

	public String getIntro() {
		return intro;
	}

	public void setIntro(String intro) {
		this.intro = intro;
	}

	public Long getParentId() {
		return parentId;
	}

	public void setParentId(Long parentId) {
		this.parentId = parentId;
	}

	public Long getSortOrder() {
		return sortOrder;
	}

	public void setSortOrder(Long sortOrder) {
		this.sortOrder = sortOrder;
	}

	public Integer getSubCategories() {
		return subCategories;
	}

	public void setSubCategories(Integer subCategories) {
		this.subCategories = subCategories;
	}

	public RecordStatus getStatus() {
		return status;
	}

	public void setStatus(RecordStatus status) {
		this.status = status;
	}

	public List<Brand> getBrands() {
		return brands;
	}

	public void setBrands(List<Brand> brands) {
		this.brands = brands;
	}

	public List<CatePropGroup> getPropGroups() {
		return propGroups;
	}

	public void setPropGroups(List<CatePropGroup> propGroups) {
		this.propGroups = propGroups;
	}
}
